package com.excel.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.excel.CELL;
import com.excel.TableModel;

/**
 * 横向属性
 * color:red etc
 * @author mike
 */
public class AttributeExcelModel extends ExcelModelIFace{
	private String[] names;
	private Map<String, ArrayList<String>> atrMap = new HashMap<String, ArrayList<String>>();	
	
	public AttributeExcelModel(TableModel tableModel, String[] names) {		
		super();
		this.tableModel = tableModel;
		this.names = names;	
	}


	public void extract() {		
		Map<String, List<CELL>> aMap = tableModel.aMap;
		for(String name : names) {
			List<CELL> aList = aMap.get(name);
			ArrayList atrValueList =  atrMap.get(name);
			if(atrValueList==null) {
				atrValueList = new ArrayList<String>();
				atrMap.put(name, atrValueList);
			}
			for(CELL aCELL : aList) {
				String position = aCELL.cellPosition;
				String[] temps = position.split("_");
				int rowIndex = Integer.parseInt(temps[0]);
				int colIndex = Integer.parseInt(temps[1])+1;
				CELL valueCELL = this.tableModel.cells[rowIndex][colIndex];
				String value = valueCELL.aTD.getAttribute("vv");
				atrValueList.add(value);
			}
		}
	}
	
	
	public List getValues(String name) {
		ArrayList atrValueList =  atrMap.get(name);
		if(atrValueList!=null) {
			return atrValueList;
		}else {
			return null;
		}
	}
	
	public String getValue(String name) {
		ArrayList atrValueList =  atrMap.get(name);
		if(atrValueList!=null) {
			return (String) atrValueList.get(0);
		}else {
			return null;
		}
	}
	
}
